from selenium import webdriver
from selenium.webdriver.common.by import By
import time


class TestCase:
    def __init__(self):
        self.drive = webdriver.Chrome()
        self.drive.get('https://ecshop.test2.shopex123.com/')

    def search(self):
        time.sleep(2)
        # 找到登录框,输入内容
        self.drive.find_element(By.ID, 'keyword').send_keys('化妆品')
        time.sleep(2)
        # 点击搜索按钮跳转
        self.drive.find_element(By.NAME, 'imageField').click()
        time.sleep(4)

    def logon(self):
        # 点击跳转注册界面
        self.drive.find_element(By.CLASS_NAME, 'reg').click()
        time.sleep(2)
        # 点击用户名输入框输入注册账户名
        self.drive.find_element(By.NAME, 'username').send_keys('luole')
        time.sleep(2)
        # 点击邮箱输入框输入注册邮箱号
        self.drive.find_element(By.NAME, 'email').send_keys('775759531@qq.com')
        time.sleep(2)
        # 点击密码框输入注册密码
        self.drive.find_element(By.NAME, 'password').send_keys('1234567')
        time.sleep(2)
        # 点击确认密码输入框再次输入密码
        self.drive.find_element(By.NAME, 'confirm_password').send_keys('1234567')
        time.sleep(2)
        # 点击同意协议按钮进行注册
        self.drive.find_element(By.NAME, 'Submit').click()
        time.sleep(2)

    def regitster(self):
        # 点击进入登入页面
        self.drive.find_element(By.CLASS_NAME, 'sign').click()
        time.sleep(2)
        # 点击输入用户名
        self.drive.find_element(By.NAME, 'username').send_keys('luole')
        time.sleep(2)
        # 点击输入密码
        self.drive.find_element(By.NAME, 'password').send_keys('1234567')
        time.sleep(2)
        # 点击登录按钮
        self.drive.find_element(By.NAME, 'submit').click()
        time.sleep(2)

    def quit(self):
        self.drive.quit()


if __name__ == '__main__':
    case = TestCase()
    # case.search()
    # case.logon()
    case.regitster()
    case.quit()
